<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">

        <ui:define name="title">
            <h:outputText value="العملاء"></h:outputText>
        </ui:define>

        <ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
            <!-- start of the login form -->
            <h:form class="well form-inline">

                <center><h1>اضافة عميل جديد</h1></center>  
                <h:panelGrid columns="2">
                  
                    <h:outputLabel value="#{bundle.CreateCustomerLabel_customerCode}" for="customerCode" />
                    <h:inputText id="customerCode" value="#{customerController.selected.customerCode}" title="#{bundle.CreateCustomerTitle_customerCode}" required="true" requiredMessage="#{bundle.CreateCustomerRequiredMessage_customerCode}"/>

                    <h:outputLabel value="#{bundle.CreateCustomerLabel_customerName}" for="customerName" />
                    <h:inputText id="customerName" value="#{customerController.selected.customerName}" title="#{bundle.CreateCustomerTitle_customerName}" required="true" requiredMessage="#{bundle.CreateCustomerRequiredMessage_customerName}"/>

                    <h:outputLabel value="#{bundle.CreateCustomerLabel_phone}" for="phone" />
                    <h:inputText id="phone" value="#{customerController.selected.phone}" title="#{bundle.CreateCustomerTitle_phone}" />

                    <h:outputLabel value="#{bundle.CreateCustomerLabel_address}" for="address" />
                    <h:inputText id="address" value="#{customerController.selected.address}" title="#{bundle.CreateCustomerTitle_address}" />

                    <h:outputLabel value="#{bundle.CreateCustomerLabel_balance}" for="balance" />
                    <h:inputText id="balance" value="#{customerController.selected.balance}" title="#{bundle.CreateCustomerTitle_balance}" />
                    <h:selectBooleanCheckbox value="#{customerController.boolean1}"/>دائن
                    <h:outputLabel value="#{bundle.CreateCustomerLabel_other}" for="other" />
                    <h:inputText id="other" value="#{customerController.selected.other}" title="#{bundle.CreateCustomerTitle_other}" />
                </h:panelGrid>
                <center>
                    <h:commandButton value="اضافه" action="#{customerController.create}" class="btn btn-primary"/>
                </center>
            </h:form>
            <!-- end of the login form -->

            <!-- start of the table -->
            <h:form>
                <center><h1>العملاء</h1></center>
                <h:panelGroup rendered="#{customerController.items.rowCount > 0}">

                    <p:dataTable  value="#{customerController.listItems}" var="item"
                                 paginator="true" rows="100"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="100,200,300" >

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_idCustomer}"/>
                            </f:facet>
                            <h:outputText value="#{item.idCustomer}"/>
                        </p:column>

                        <p:column  filterBy="#{item.customerCode}"  >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_customerCode}"/>
                               
                            </f:facet>
                            <h:outputText value="#{item.customerCode}"/>
                        </p:column>

                        <p:column filterBy="#{item.customerName}" >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_customerName}"/>
                            </f:facet>
                            <h:outputText value="#{item.customerName}"/>
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_phone}"/>
                            </f:facet>
                            <h:outputText value="#{item.phone}"/>
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_address}"/>
                            </f:facet>
                            <h:outputText value="#{item.address}"/>
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_balance}"/>
                            </f:facet>
                           <h:panelGroup rendered="#{item.balance eq 0}" >

                                #{item.balance}
                                    </h:panelGroup>
                            <h:panelGroup rendered="#{item.balance lt 0}">
                                
                                  #{(item.balance)*-1 }
                               دائن
                                    </h:panelGroup>
                                 <h:panelGroup rendered="#{item.balance gt 0}" >
                                   
                                    #{item.balance}
                                    </h:panelGroup>
                             
                            
                            
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerTitle_other}"/>
                            </f:facet>
                            <h:outputText value="#{item.other}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <h:commandButton action="#{customerController.prepareView(item)}" value="#{bundle.ListCustomerViewLink}" class="btn btn-primary"/>
                            <h:panelGroup    rendered="${limits==0}">
                            <h:outputText value=" "/>
                            <h:commandButton action="#{customerController.prepareEdit(item)}" value="#{bundle.ListCustomerEditLink}" class="btn btn-primary"/>
                            <h:outputText value=" "/>
                            <h:commandButton action="#{customerController.destroy(item)}" value="#{bundle.ListCustomerDestroyLink}" class="btn btn-primary"/>
                            <h:outputText value=" "/>
                            </h:panelGroup>
                            <h:commandButton action="#{customerController.bills(item)}" value="#{bundle.getBills}" class="btn btn-primary"/>
                        </p:column>
                    </p:dataTable>

                </h:panelGroup>



            </h:form>                


            <!-- end of the table -->
            <div class="clear"></div>
            <button style="margin-right: 500px;" class="btn btn-primary" type="button">اطبع</button>


        </ui:define>
    </ui:composition>
</html>
